package net.sareweb.acab.session;

import net.sareweb.acab.entity.*;
import java.util.ArrayList;
import java.util.List;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

@Name("cityHome")
public class CityHome extends EntityHome<City> {

	@In(create = true)
	StateHome stateHome;

	public void setCityIdCity(Integer id) {
		setId(id);
	}

	public Integer getCityIdCity() {
		return (Integer) getId();
	}

	@Override
	protected City createInstance() {
		City city = new City();
		return city;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		State state = stateHome.getDefinedInstance();
		if (state != null) {
			getInstance().setState(state);
		}
	}

	public boolean isWired() {
		if (getInstance().getState() == null)
			return false;
		return true;
	}

	public City getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

	public List<Request> getRequestsForFromCity() {
		return getInstance() == null ? null : new ArrayList<Request>(
				getInstance().getRequestsForFromCity());
	}

	public List<Request> getRequestsForToCity() {
		return getInstance() == null ? null : new ArrayList<Request>(
				getInstance().getRequestsForToCity());
	}

	public List<Travel> getTravelsForToCity() {
		return getInstance() == null ? null : new ArrayList<Travel>(
				getInstance().getTravelsForToCity());
	}

	public List<Travel> getTravelsForFromCity() {
		return getInstance() == null ? null : new ArrayList<Travel>(
				getInstance().getTravelsForFromCity());
	}

}
